package org.aeon.colorfulplanebattle.view.components;

import javax.swing.*;
import java.awt.*;

import static org.aeon.colorfulplanebattle.constant.GameBasisConstant.COLOR_BLOCK_HEIGHT;
import static org.aeon.colorfulplanebattle.constant.GameBasisConstant.COLOR_BLOCK_WIDTH;

/**
 * @author: MissingAeon
 * @date: 2024/1/8 19:13
 * @description:
 */
public class ColorBlock extends JComponent {
    private Color color;

    public ColorBlock(Color color) {
        // this.setBounds(0,0,COLOR_BLOCK_WIDTH, COLOR_BLOCK_HEIGHT);
        this.setPreferredSize(new Dimension(COLOR_BLOCK_WIDTH, COLOR_BLOCK_HEIGHT));
        this.color = color;
    }

    public Color getColor() {
        return color;
    }

    public void setColor(Color color) {
        this.color = color;
    }

    // paint函数画出实心形状
    public void paintComponent(Graphics g) {
        // 画笔更换颜色
        g.setColor(color);
        // 设置填充位置和大小
        g.fillRect(3, 5, COLOR_BLOCK_WIDTH - 10, COLOR_BLOCK_HEIGHT - 5);
    }
}
